<!DOCTYPE html>
<html lang="en">

<head>
	<title></title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" href="../res/css/weui.css" />
	<link rel="stylesheet" href="../res/css/weuix.css" />
	<link rel="stylesheet" href="../res/css/common.css" />
	<script src="../res/js/zepto.min.js"></script>
	<script src="../res/js/zepto.weui.js"></script>
	<script src="../res/js/common.js?v=2"></script>
	<script src="../res/js/template-web.js"></script>
	<script type="text/javascript">
		var startTime = "",
			endTime = "",
			startTimeString = "",
			endTimeString = "";
		$(function () {
			var user_id = getQst('user_id').trim();

			function getHistory() {
				var paramJson = {
					"current": 1, //当前页,示例值(1)
					"endTime": "", //结束时间
					"size": 100, //每页大小,示例值(10)
					"startTime": "" //开始时间
				}
				newAjaxPost('/h5/myInterrogation/getInterrogationHistoryList', paramJson, getHistoryOk)
			}

			getHistory()

			function getHistoryOk(res) {
				var inquiryData = res.data;
				var data = {}
				if (inquiryData.list.length > 0) {
					$(".noFind").hide()
					$("#videoInquiry").show()
					var videoArr = inquiryData.list.filter((item) => {
						return item;
					})
					data.videoArr = videoArr;
					var diagnosisList = []
					if (videoArr.length != []) {
						videoArr.forEach(element => {
							diagnosisList.push(JSON.parse(element.diagnosis))
						});
					}
					//   视频问诊
					if (videoArr.length > 0) {
						for (var i = 0; i < videoArr.length; i++) {
							//生成html片段
							var html = template("videoInquiryList", data);
							var container = document.getElementById("videoInquiry");
							//将html片段渲染到界面中
							container.innerHTML = html;
							// return
						}
					}

					//诊断渲染
					var diagnosisSpan = document.querySelectorAll("#diagnosis")
					diagnosisList.forEach((item, index) => {
						// console.log(item);
						if (item) {
							item.forEach((ele, i) => {
								if(i!=item.length-1){
									diagnosisSpan[index].innerText += ele.diagnosis+",";
								}
								else{
									diagnosisSpan[index].innerText += ele.diagnosis;
								}
							})
						} else {}
					})
				}
				else{
					$("#videoInquiry").hide()
					$(".noFind").show()
				}

			}

			// 后退
			$('#btnBack').click(function () {
				goPageNo(-1);
			});
			// 健康指导导航
			$('#inquiry_tab>div>div').on('click', function () {
				var idx = $("#inquiry_tab>div>div").index(this);
				$(this).addClass("tab-green").siblings().removeClass("tab-green");
				$(".inquiry_body li").hide().eq(idx).show();
			})

			//选择时间
			$("#start-time").datetimePicker({
				title: '限定年月',
				years: [2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023],
				monthes: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
				onClose: function (p, v, d) {
					startTime = "";
					startTimeString = "";
					p.value.forEach((item, index) => {
						startTimeString += item;
						if (index <= 2) {
							if (index == 2) {
								startTime += item + " ";
							} else {
								startTime += item + '-';
							}
						} else {
							startTime += item + ':';
						}
					})
					startTime = startTime + '00';
					if (endTimeString == "" || startTimeString < endTimeString) {
						console.log(1);
						var paramJson = {
							"current": 1, //当前页,示例值(1)
							"endTime": endTime, //结束时间
							"size": 100, //每页大小,示例值(10)
							"startTime": startTime //开始时间
						}
						newAjaxPost('/h5/myInterrogation/getInterrogationHistoryList', paramJson,
							getHistoryOk)
					} else {
						msgInfo("结束时间不可早于开始时间")
					}
				}
			});
			$("#end-time").datetimePicker({
				title: '限定年月',
				years: [2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023],
				monthes: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
				onClose: function (p, v, d) {
					endTime = "";
					endTimeString = "";
					p.value.forEach((item, index) => {
						endTimeString += item;
						if (index <= 2) {
							if (index == 2) {
								endTime += item + " ";
							} else {
								endTime += item + '-';
							}
						} else {
							endTime += item + ':'
						}
					})
					endTime = endTime + '00'
					console.log(endTime);
					console.log(endTimeString);
					if (startTimeString == "" || startTimeString < endTimeString) {
						var paramJson = {
							"current": 1, //当前页,示例值(1)
							"endTime": endTime, //结束时间
							"size": 100, //每页大小,示例值(10)
							"startTime": startTime //开始时间
						}
						newAjaxPost('/h5/myInterrogation/getInterrogationHistoryList', paramJson,
							getHistoryOk)
					} else {
						msgInfo("结束时间不可早于开始时间")
					}
				}
			});
		})
	</script>
</head>
<style>
	.weui-navbar {
		background-color: #ffffff;
	}

	.prescriptionlist {
		overflow: hidden;
		position: relative;
		padding: 12px;
		background: #ffffff;
		margin: 15px;
		border-radius: 10px;
		padding-bottom: 8px;
	}

	.prescriptionlist_image {
		width: 56px;
		height: 56px;
		border-radius: 50%;
		overflow: hidden;
		float: left;
	}

	.prescriptionlist_name {
		font-size: 15px;
		float: left;
		width: 77%;
		height: 56px;
		line-height: 28px;
		margin-left: 10px;
	}

	.nickname {
		color: #353535;
		width: 61px;
		height: 19px;
		border-radius: 5px;
		font-size: 14px;
		padding: 2px 8px;
		/* margin-left: 70px; */
	}

	.lrsj {
		display: inline-block;
		width: 270px;
		float: left;
		font-size: 14px;
		color: #353535;
	}

	.prescriptionlist_type,
	.prescriptionlist_id {
		font-size: 14px;
		color: #353535;
		margin: 2px 0;
		padding: 5px 0;
	}

	.prescriptionlist .prescriptionlist_type:nth-child(6) {
		border-bottom: 1px solid #f8f7f7;
		padding-top: 0px;
	}

	.goAgain {
		width: 30%;
		font-size: 15px;
		line-height: 30px;
		height: 30px;
		margin: 5px 10px;
		display: inline-block;
		float: right;
		color: #03A6FF;
		text-align: center;
		border: 2px solid #03A6FF;
		border-radius: 19px;
	}

	.button {
		width: 30%;
		border-radius: 10px;
		background: #1189FF;
		font-size: 13px;
		line-height: 30px;
		height: 30px;
		margin: 5px 10px;
		margin-top: 5px;
		display: inline-block;
		float: right;
		color: white;
		text-align: center;
		border: 2px solid #1189FF;
		border-radius: 19px;
	}

	.prescriptionlist_message {
		width: 95%;
		margin: 15px 2.5%;
		background: #FBFBFB;
		border-radius: 20px;
		font-size: 14px;
		font-family: PingFang SC;
		font-weight: 500;
		color: #757575;
	}

	.prescriptionlist_message div {
		padding: 10px 0;
		display: flex;
		justify-content: center;
	}

	.prescriptionlist_message div span:nth-child(1) {
		width: 30%;
		text-align-last: justify;
		margin-left: 5%;
	}

	.prescriptionlist_message div span:nth-child(2) {
		width: 65%;
	}

	.fixed-top {
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 100;
	}

	.pickerWrappar {
		margin-top: 60px;
		display: flex;
	}

	.triangle {
		width: 15px;
		height: 15px;
		position: absolute;
		top: 5px;
		right: 10px;
	}

	.weui-cell__bd {
		position: relative;
	}

	section {
		margin-top: 10px;
	}

	.noFind {
            width: 90%;
            margin: 10px 2.5%;
            display: block;
            text-align: center;
            overflow: hidden;
            font-size: 15px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #353535;
            background-color: #F9F8FE;
        }

        .noFind img {
            width: 198px;
            height: 158px;
            border: none;
            border-radius: 0px;
            margin: 15px;
        }
</style>

<body ontouchstart>
	<header>
		<div class="fixed-top">
			<div class="weui-btn_primary weui-header">
				<div class="weui-header-left"><a id="btnBack" class="icon icon-109"></a></div>
				<h1 class="weui-header-title">我的问诊</h1>
			</div>
		</div>
	</header>
	<div class="pickerWrappar">
		<div class="weui-cell">
			<div class="weui-cell__bd">
				<input class="weui-input" id="start-time" type="text" value="" placeholder="请选择开始时间">
				<img src="../res/images/icon_put_away@2x.png" alt="" class="triangle">
			</div>
		</div>
		<div class="weui-cell">
			<div class="weui-cell__bd">
				<input class="weui-input" id="end-time" type="text" value="" placeholder="请选择结束时间">
				<img src="../res/images/icon_put_away@2x.png" alt="" class="triangle">
			</div>
		</div>
	</div>
	<!-- 主体 -->
	<section>
		<ul class="inquiry_body">
			<li id="videoInquiry" style="display: block;">
				
			</li>
			<div class="weui-cell noFind" style="display: none;"><img src="../res/images/img_empty_state@2x.png" alt=""><p>暂无消息~</p></div>
		</ul>
	</section>
</body>
<!-- 视频问诊列表 -->
<script id="videoInquiryList" type="text/html">
	{{each videoArr as value}}
	<div class="prescriptionlist">
		<div class="prescriptionlist_image"><img src="{{value.doctorHeadImg}}"></div>
		<div class="prescriptionlist_name">{{value.trueName}}
			<span class="nickname">{{value.createTime}}</span>
			<span class="lrsj"> {{value.departmentName}} | {{value.doctorJobTitle}} </span>
		</div>
		<div class="clear"></div>
		<div class="prescriptionlist_message">
			<div><span>问 诊 人：</span><span>{{value.userName}}</span></div>
			<div><span>问诊方式：</span><span>
					{{if value.inquiryType == 1}}
					视频问诊
					{{else if value.inquiryType == 2}}
					图文问诊
					{{else if value.inquiryType == 3}}
					家庭医生
					{{else}}
					复诊
					{{/if}}</span></div>
			<div><span>诊 断：</span><span id="diagnosis"></span></div>
		</div>
		<div class="button" onclick="goPage('my_prescription_list.htm?logId='+{{value.id}})">问诊详情
		</div>
		<div class="goAgain" onclick="goPage('doctor_home_page.htm?log_type=0&doctor_id='+{{value.doctorId}})">再次问诊</div>
	</div>
	{{/each}}
</script>

</html>